package com.lmc.form.dao.dal.auto;



import com.free.bsf.core.util.ConvertUtils;
import com.free.bsf.core.db.DbConn;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import lombok.*;
import java.util.Date;
import com.lmc.form.dao.model.auto.*;

/**
 * paas_form_model_history 表自动dal映射,不要手工修改
 * 表单历史表(存储废弃表单)
 * @author 车江毅
 * @since 2022-04-30 22:27:34
 * 自动生成: https://gitee.com/makejava/EasyCode/wikis/
 */
public class paas_form_model_history_base_dal {

    public boolean add(DbConn conn, paas_form_model_history_model model) {
        val par = new Object[]{
            /**表单唯一标识,前台传入,不可改变*/
            model.form_key,
            /**表单名称,用于用户识别区分*/
            model.form_name,
            /**表单类型,0=主表单,1=扩展表单,2=子表单*/
            model.form_type,
            /**表单设计类型,0=绝对定位表单,1=相对定位表单*/
            model.form_design_type,
            /**表单模型内容,json或html等,根据表单类型不同，则模型不同*/
            model.form_design_model,
            /**表单控件属性模型,json,仅存储后台协议性属性*/
            model.form_control_property_model,
            /**表单所属用户,一般为企业用户标识*/
            model.form_create_user,
            /**版本号,用于区分不同版本表单*/
            model.version,
            /***/
            model.create_time,
            /***/
            model.update_time,
            /***/
            model.create_user,
            /***/
            model.update_user,
            /**表单事件流,json,用于后台解析事件*/
            model.form_design_event,
            /**表单数据源json,用于后台解析事件*/
            model.form_design_datasource
        };
        int rev = conn.executeSql("insert into paas_form_model_history(form_key,form_name,form_type,form_design_type,form_design_model,form_control_property_model,form_create_user,version,create_time,update_time,create_user,update_user,form_design_event,form_design_datasource)" +
                "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)", par);
        return rev == 1;
    }

    public boolean edit(DbConn conn, paas_form_model_history_model model) {
       val par = new Object[]{
           /**表单唯一标识,前台传入,不可改变*/
            model.form_key,
           /**表单名称,用于用户识别区分*/
            model.form_name,
           /**表单类型,0=主表单,1=扩展表单,2=子表单*/
            model.form_type,
           /**表单设计类型,0=绝对定位表单,1=相对定位表单*/
            model.form_design_type,
           /**表单模型内容,json或html等,根据表单类型不同，则模型不同*/
            model.form_design_model,
           /**表单控件属性模型,json,仅存储后台协议性属性*/
            model.form_control_property_model,
           /**表单所属用户,一般为企业用户标识*/
            model.form_create_user,
           /**版本号,用于区分不同版本表单*/
            model.version,
           /***/
            model.create_time,
           /***/
            model.update_time,
           /***/
            model.create_user,
           /***/
            model.update_user,
           /**表单事件流,json,用于后台解析事件*/
            model.form_design_event,
           /**表单数据源json,用于后台解析事件*/
            model.form_design_datasource,
            model.id
        };
        int rev = conn.executeSql("update paas_form_model_history set form_key=?,form_name=?,form_type=?,form_design_type=?,form_design_model=?,form_control_property_model=?,form_create_user=?,version=?,create_time=?,update_time=?,create_user=?,update_user=?,form_design_event=?,form_design_datasource=? where id=?", par);
        return rev == 1;

    }

    public boolean delete(DbConn conn, Integer id) {
        val par = new Object[]{id};
        String Sql = "delete from paas_form_model_history where id=?";
        int rev = conn.executeSql(Sql, par);
        if (rev == 1) {
            return true;
        } else {
            return false;
        }
    }

    public paas_form_model_history_model get(DbConn conn, Integer id) {
        val par = new Object[]{id};
        val stringSql = new StringBuilder();
        stringSql.append("select s.* from paas_form_model_history s where s.id=?");
        val ds = conn.executeList(stringSql.toString(), par);
        if (ds != null && ds.size() > 0) {
            return createModel(ds.get(0));
        }
        return null;
    }

    public ArrayList<paas_form_model_history_model> list(DbConn conn) {
        val rs = new ArrayList<paas_form_model_history_model>();
        val stringSql = new StringBuilder();
        stringSql.append("select s.* from paas_form_model_history s ");
        val ds = conn.executeList(stringSql.toString(), new Object[]{});
        if (ds != null && ds.size() > 0) {
            for (Map<String, Object> dr : ds) {
                rs.add(createModel(dr));
            }
        }
        return rs;
    }

    public paas_form_model_history_model createModel(Map<String, Object> dr) {
        val o = new paas_form_model_history_model();
        /***/
        if (dr.containsKey("id")) {
            o.id = ConvertUtils.convert(dr.get("id"),Integer.class);
        }
        /**表单唯一标识,前台传入,不可改变*/
        if (dr.containsKey("form_key")) {
            o.form_key = ConvertUtils.convert(dr.get("form_key"),String.class);
        }
        /**表单名称,用于用户识别区分*/
        if (dr.containsKey("form_name")) {
            o.form_name = ConvertUtils.convert(dr.get("form_name"),String.class);
        }
        /**表单类型,0=主表单,1=扩展表单,2=子表单*/
        if (dr.containsKey("form_type")) {
            o.form_type = ConvertUtils.convert(dr.get("form_type"),Integer.class);
        }
        /**表单设计类型,0=绝对定位表单,1=相对定位表单*/
        if (dr.containsKey("form_design_type")) {
            o.form_design_type = ConvertUtils.convert(dr.get("form_design_type"),Integer.class);
        }
        /**表单模型内容,json或html等,根据表单类型不同，则模型不同*/
        if (dr.containsKey("form_design_model")) {
            o.form_design_model = ConvertUtils.convert(dr.get("form_design_model"),String.class);
        }
        /**表单控件属性模型,json,仅存储后台协议性属性*/
        if (dr.containsKey("form_control_property_model")) {
            o.form_control_property_model = ConvertUtils.convert(dr.get("form_control_property_model"),String.class);
        }
        /**表单所属用户,一般为企业用户标识*/
        if (dr.containsKey("form_create_user")) {
            o.form_create_user = ConvertUtils.convert(dr.get("form_create_user"),String.class);
        }
        /**版本号,用于区分不同版本表单*/
        if (dr.containsKey("version")) {
            o.version = ConvertUtils.convert(dr.get("version"),Integer.class);
        }
        /***/
        if (dr.containsKey("create_time")) {
            o.create_time = ConvertUtils.convert(dr.get("create_time"),Date.class);
        }
        /***/
        if (dr.containsKey("update_time")) {
            o.update_time = ConvertUtils.convert(dr.get("update_time"),Date.class);
        }
        /***/
        if (dr.containsKey("create_user")) {
            o.create_user = ConvertUtils.convert(dr.get("create_user"),String.class);
        }
        /***/
        if (dr.containsKey("update_user")) {
            o.update_user = ConvertUtils.convert(dr.get("update_user"),String.class);
        }
        /**表单事件流,json,用于后台解析事件*/
        if (dr.containsKey("form_design_event")) {
            o.form_design_event = ConvertUtils.convert(dr.get("form_design_event"),String.class);
        }
        /**表单数据源json,用于后台解析事件*/
        if (dr.containsKey("form_design_datasource")) {
            o.form_design_datasource = ConvertUtils.convert(dr.get("form_design_datasource"),String.class);
        }
        return o;
    }
}


